package com.zysd.collection.scheduler.condition;

import org.springframework.util.StringUtils;

/**
 * 分页查询条件
 *
 * @author liuht
 * @date 2017/10/13 10:33
 */
public class PageCondition {

    private Integer page;

    private Integer rows;

    private Integer offset;

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    public Integer getOffset() {
        if(null != this.offset){
            return offset;
        }
        return  (null == this.rows || null ==  this.page) ? 0 : (this.page -1) * rows;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getRows() {
        return rows;
    }

    public void setRows(Integer rows) {
        this.rows = rows;
    }

    /**
     * 检查分页参数
     * @return 结果
     */
    public boolean checkPageParam() {
        return (!StringUtils.isEmpty(page) && !StringUtils.isEmpty(rows)) || (!StringUtils.isEmpty(rows) && !StringUtils.isEmpty(offset));
    }
}
